<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/23/023
 * Time: 9:09
 */

namespace Lib\Utils;


class ArrayUtils
{

    public static function ToArray($data){
        return is_array($data) ? $data : func_get_args();
    }
    public static function MapToMapArray($map){
        $data=[];
        foreach ($map as $key=>$value)
        {
            $data[]=["name"=>$key,"value"=>$value];
        }
        return $data;
    }
    public static function ArrayToMapArray($array,$keyname,$valuename){
        $data=[];
        foreach ($array as $value)
        {
            $data[]=["name"=>$value->$keyname,"value"=>$value->$valuename];
        }
        return $data;
    }

    public static function ArrayToArrayMap($array,$keyname){
        $data=[];
        foreach ($array as $value)
        {
            $data[$value->$keyname][]=$value;
        }
        return $data;
    }
    public static function ArrayToKeyMap($array,$keyname){
        $data=[];
        foreach ($array as $value)
        {
            $data[$value->$keyname]=$value;
        }
        return $data;
    }
    public static function MapSetToMap($MapSet,$keyname,$valuename){
        $data=[];
        foreach ($MapSet as $item)
        {
            $data[$item->$keyname]=$item->$valuename;
        }
        return $data;
    }
}